// pages/identification/identification.js
import http from "../../utils/baseApi.js";

Page({
	// 页面的初始数据
	data: {
		userInfo: null,
		strUserId: "",
    	nickname: "",
		mobile: "",
		strBank: "",
		strAccount: "",
		strCardNumber: "",
		status: "none"
	},
	// 页面加载
	onLoad: function () {
		let that = this;
		let userInfo = wx.getStorageSync("userInfo"); 
		that.setData({ strUserId:userInfo.intUserId });
	},
	// 页面显示
	onShow: function () {
		let that = this;
		let userInfo = wx.getStorageSync("userInfo");
		that.setData({ userInfo:userInfo, mobile:userInfo.strMobile });
		if (userInfo.strRealName != null) {
			that.setData({ nickname:userInfo.strRealName });
		}
		// 已经通过审核
		if (userInfo.isAgent == 1 && userInfo.isAgentDeleted == 0) {
			that.setData({ status:"success" });
		} else if (userInfo.isAgent == 0 && userInfo.isAgentDeleted == 0) {
			that.setData({ status:"wait" });
		}
	},
	// 输入银行卡号
	onBindCardNumber: function (e) {
		let that = this;
		that.setData({ strCardNumber:e.detail.value });
	},
	// 输入开户名
	onBindAccount: function (e) {
		let that = this;
		that.setData({ strAccount:e.detail.value });
	},
	// 输入银行卡号
	onBindBank: function (e) {
		let that = this;
		that.setData({ strBank:e.detail.value });
	},
	// 保存个人资料
	save: function () {
		let that = this;
		http.post("sale/province-agent/edit",{
			strUserId:that.data.strUserId,
			strCardNumber:that.data.strCardNumber,
			strAccount:that.data.strAccount,
			strBank:that.data.strBank
		}).then((res)=>{
			if (res.code == 2000) {
				wx.showToast({ title:"已提交认证!", icon:"success", duration:1500, mask:true });
				let timer = setTimeout(()=>{
					clearTimeout(timer);
					wx.navigateBack();
				},1500);
			} else {
				wx.showToast({ title:res.message, duration:1500, icon:"none", mask:true });
			}
		});
	},
	// 显示省代理列表
	turn2list: function () {
		wx.navigateTo({ url:"/pages/worker/worker" });
	}
})